from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from django.conf import settings
def dumps(json_dict,expires):
    #加密
    # 1.创建对象
    serializer = Serializer(settings.SECRET_KEY, expires)
    # 2.加密
    json_str = serializer.dumps(json_dict)
    # 3.返回字符串
    return json_str.decode()



def loads(json_str,expires):
    #解密
    # 1.创建对象
    serializer = Serializer(settings.SECRET_KEY, expires)
    # 2.解密
    json_dict = serializer.loads(json_str)
    # 3.返回字典
    return json_dict